# Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
# This source file is part of the Cangjie project, licensed under Apache-2.0
# with Runtime Library Exception.
#
# See https://cangjie-lang.cn/pages/LICENSE for license information.

from os import path

integer_types = ['Int8', 'Int16', 'Int32', 'Int64', 'IntNative', 'UInt8', 'UInt16', 'UInt32', 'UInt64', 'UIntNative']
number_types = integer_types + ['Float16', 'Float32', 'Float64']
other_types = ['String', 'Rune', 'Bool', 'Unit', '(Int8, Int8)', 'Array<Int8>', 'C']
types = number_types + other_types
default_value_map = {'Bool' : 'true', 'Unit' : '()', 'Array<Int8>' : '[1]', 'Rune' : "'1'", 'String' : '"1"', '(Int8, Int8)' : '(1i8, 1i8)', 'C' : 'C(1)'}
ops = ['+', '-', '*', '/', '%', '&&', '||', '&', '|', '^', '<<', '>>']

def default_value(ty : str) -> str:
  if ty in integer_types: return '1'
  if 'Float' in ty: return '1.0'
  return default_value_map[ty]

def valid_types(op: str) -> list:
  if op in ['%', '<<', '>>', '|', '&', '^']: return integer_types
  if op in ['&&', '||']: return ['Bool']
  return number_types

dir = path.dirname(path.realpath(__file__))
path = dir + '/test_' + path.basename(dir) + '_{}.cj'
template = '''
/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
 * This source file is part of the Cangjie project, licensed under Apache-2.0
 * with Runtime Library Exception.
 *
 * See https://cangjie-lang.cn/pages/LICENSE for license information.
 */

/*
  @Assertion:   4.23(23) Since a compound assignment expression is also an assignment expression, the compound
                assignment operator is also non-combining.
  @Description: %s
  @Mode: %s
  @Negative: %s
  @Structure: single
  @CompileWarning: ignore
  @Comment: Auto-generated by gen.py
*/
%s'''
negative_template = template % ('Checks that the expression a {op}= b {op}= c is invalid for type {t}.', 'compileonly', 'yes', '''
main() {{
    var v : {t} = {v}
    v {op}= v {op}= v
    0
}}
''')
counter = 1

def write_counted(contents : str):
  global counter
  with open(path.format(str(counter).zfill(3)), 'w') as file:
    file.write(contents)
    counter += 1

tests = [negative_template.format(t=t, v=default_value(t), op=op) for op in ops for t in valid_types(op)]
for test in tests:
  write_counted(test)
